<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:o="http://omnifaces.org/ui">
    <o:importConstants type="vn.vfriends.vcms.admin.model.RoleCode"/>
    <f:view contentType="text/html">    
        <h:head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <title><ui:insert name="title">VCMS</ui:insert></title>
            <style type="text/css">
                .ui-widget {
                    font-family: Tahoma;
                    font-size: 11px;
                }
            </style>
        </h:head>
        <h:body>
            <h:outputStylesheet library="css" name="component.css"/>
            <ui:insert name="idleMonitor">
                <h:form id="monitorForm" prependId="false">
                    <p:idleMonitor timeout="#{session.maxInactiveInterval * 1000}" onidle="idleDialog.show();" 
                                   onactive='window.location = "#{request.contextPath}/home.jsf";'/>

                    <p:dialog header="Thông báo" resizable="false" widgetVar="idleDialog" modal="true" width="400">
                        <h:outputText value="Phiên làm việc đã hết hạn" />
                    </p:dialog>
                </h:form>
            </ui:insert>
            
            <ui:insert name="dialog"></ui:insert>
            
            <p:layout fullPage="true">
                <p:layoutUnit position="north" closable="false" resizable="false" size="50">
                    <h:form id="headerForm" prependId="false">
                        <h:panelGrid columns="2" width="100%">
                            <h:panelGroup style="display: inline; float: left; padding: 5px;">
                                <h:outputText value="VCMS" style="font-size: 14px; font-weight: bold;"/>
                            </h:panelGroup>
                            <h:panelGroup style="display: inline; float: right; padding-right: 5px;">
                                <h:outputText value="#{securityBean.loggedUser.username}" style="padding-left: 10px;" 
                                              rendered="#{securityBean.loggedUser != null}"/>
                                
                                <p:commandLink id="logout" action="#{securityBean.logoutAction()}" ajax="false" value="Đăng xuất" style="padding-left: 10px;" 
                                               rendered="#{securityBean.loggedUser != null}"/>
                                <p:commandLink id="login" action="login" ajax="false" value="Đăng nhập" style="padding-left: 10px;" 
                                               rendered="#{securityBean.loggedUser == null}"/>
                            </h:panelGroup>
                        </h:panelGrid>
                    </h:form>
                </p:layoutUnit>
                
                <ui:insert name="leftLayout">
                    <p:layoutUnit position="west" header="Menu" size="250" resizable="true" collapsible="true" rendered="#{securityBean.loggedUser != null}">
                        <h:form id="menuForm">
                            <p:menu style="width: 90%; margin-top: 2px; margin-left: auto; margin-right: auto;">  
                                <p:submenu label="Quản trị hệ thống" rendered="#{securityBean.isUserInRole(RoleCode.SYSADMIN)}">  
                                    <p:menuitem value="Quản lý người dùng" url="/admin/user/list.jsf" ajax="false" rendered="#{securityBean.isUserInRole(RoleCode.SYSADMIN)}"/>
                                    <p:menuitem value="Quản lý quyền truy cập" url="/admin/role/list.jsf" ajax="false" rendered="#{securityBean.isUserInRole(RoleCode.SYSADMIN)}"/>
                                </p:submenu>
                                <p:submenu label="Quản trị nội dung" rendered="#{securityBean.isUserInRole(RoleCode.ADMIN) || securityBean.isUserInRole(RoleCode.EDITOR)}">  
                                    <p:menuitem value="Quản lý danh mục" url="/category/list.jsf" ajax="false" rendered="#{securityBean.isUserInRole(RoleCode.ADMIN)}"/>
                                    <p:menuitem value="Quản lý bài viết" url="/item/list.jsf" ajax="false" 
                                                rendered="#{securityBean.isUserInRole(RoleCode.ADMIN) || securityBean.isUserInRole(RoleCode.EDITOR)}"/>
                                    <p:menuitem value="Quản lý file" url="/filemanager.jsf" ajax="false" 
                                                rendered="#{securityBean.isUserInRole(RoleCode.SYSADMIN) || securityBean.isUserInRole(RoleCode.ADMIN)}"/>
                                </p:submenu>
                            </p:menu>
                        </h:form>
                    </p:layoutUnit>
                </ui:insert>
                
                <p:layoutUnit position="center" closable="true" collapsible="true">
                    <h:form id="statusForm" prependId="false">
                        <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>  

                        <p:dialog modal="false" widgetVar="statusDialog" header="Trạng thái"   
                                  draggable="false" closable="false">  
                            <p:graphicImage value="#{resource['images:ajaxloadingbar.gif']}" />  
                        </p:dialog>
                    </h:form>
                    <ui:insert name="content"></ui:insert>
                </p:layoutUnit>
            </p:layout>
        </h:body>
    </f:view>    
</html>
